<?php
if (!defined("_ECRIRE_INC_VERSION")) return;

include_spip('inc/meta');
include_spip('base/create');
function pdk_upgrade($nom_meta_base_version, $version_cible) {
	$current_version = "0.0";
    // If plugin is already installed, get it's base version
	if (isset($GLOBALS['meta'][$nom_meta_base_version])) {
		$current_version = $GLOBALS['meta'][$nom_meta_base_version];		
	}
	
    // If plugin's base version is 0.0 (it is not installed) create database
	if ($current_version=="0.0") {
		creer_base();
        // Write new version to sql cache. 
        //$current_version became latest, therefore all next version_compare checks won't be executed
		ecrire_meta($nom_meta_base_version, $current_version=$version_cible);		
	}
    
    // If plugin's base version is < $cur_dev_version, create and alter all tables
    $cur_dev_version = "0.1.0";
    if (version_compare($current_version,$cur_dev_version,"<")) {
        //Create all uncreated yet tables
        creer_base();
        
        // Upgrade via maj_tables (it tells SPIP to alter tables if there are some new fields)
        maj_tables('spip_pdk_products');
        maj_tables('spip_pdk_products_descriptions');
        maj_tables('spip_pdk_categories');
        
        // Write new version to sql cache
        ecrire_meta($nom_meta_base_version, $current_version=$cur_dev_version);
    }
    
    // Populate database
    include_spip('base/alohacart_db_populate');
}

// fonction de desinstallation
function pdk_vider_tables($nom_meta_base_version) {
   
   sql_drop_table('spip_pdk_products'); 
   sql_drop_table('spip_pdk_products_descriptions');
   sql_drop_table('spip_pdk_categories');
   
   effacer_meta($nom_meta_base_version);
}
?>